/*
 * Copyright (c) 2023, 2023,yzc.cn All rights reserved.
 *
 */
package cn.yzc.controller;

import cn.yzc.pojo.Orders;
import cn.yzc.pojo.Result;
import cn.yzc.server.OrdersServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>Project: redis - OrdersController</p>
 * <p>Powered by yzc On 2023-12-14 09:24:31</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@RestController
public class OrdersController {
    @Autowired
    OrdersServer ordersServer;
   //保存订单，将订单存入redis
    @PostMapping("/orders/save")
    public Result save(@RequestBody Orders orders){
      int rs =  ordersServer.save(orders);
      if (rs != 0)
       return Result.success("保存订单成功");
      return Result.error("保存订单失败");
    }
   //支付成功，将订单加入数据库
    @GetMapping("/orders/pay")
    public Result pay(String oid){
        int rs = ordersServer.pay(oid);
        if (rs != 0)
        return Result.success("支付成功");
       return Result.error("支付失败");
    }

    //根据订单编号查询订单明细
    @GetMapping("/order/queryOid")
    public Result queryOid(String oid){
        Orders orders = ordersServer.queryOid(oid);
        return Result.success(orders);
    }

}
